// pages/diamonddetail/diamonddetail.js
let md5 = require("../../utils/md5.js")
let axios = require("../../utils/util.js")
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    diamondNum:1,//类型id/类型下标+1
    diamondList:[],//明细列表
    diatopList:["充值记录","消费记录"],//类型列表
    diamondpage:1//页数
  },
  //切换类型
  diamondNumChange(data){
    // console.log(data)
    this.setData({
      diamondNum:data.currentTarget.dataset.index+1,
      diamondList:[],
      diamondpage:1
    })
    this.getDiamond()
  },
  //获取明细
  getDiamond(){
    let timestamp = (Date.parse(new Date()) / 1000).toString();
    let _token =
      "userId=" +
      app.globalData.user_id +
      "&type=" +
     this.data.diamondNum +
      "&token=" +
      app.globalData.userToken +
      "&time=" +
      timestamp +
      "&page=" +
      this.data.diamondpage +
      "&wPQvCAOU$lbIyg9o2wVg0Dt1k^zy&SaX";
    let params = {
      userId: app.globalData.user_id,
      token: app.globalData.userToken,
      page:this.data.diamondpage,
      type:this.data.diamondNum,
      time: timestamp,
      sign: md5.hexMD5(_token),
    };
    axios.axios({
      url: "/user/diamondLogAccount",
      data: params
    }).then((res) => {
      console.log(res.data.result),
        this.setData({
          diamondList: this.data.diamondList.concat(res.data.result.flowFormList),
        })
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getDiamond()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.setData({
      diamondpage:this.data.diamondpage+1
    })
    this.getDiamond()
    console.log(11)
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})